<template>
    <div>
        <van-action-bar>
            <van-action-bar-icon icon="chat-o" text="客服" dot />
            <van-action-bar-icon icon="cart-o" text="购物车" badge="5" to="/CartView"/>
            <van-action-bar-icon icon="shop-o" text="店铺" badge="12" />
            <van-action-bar-button type="warning" text="加入购物车" @click="addToCart" />
            <van-action-bar-button type="danger" text="立即购买" />
        </van-action-bar>
    </div>
</template>

<script>
import { doAddCart } from '@/apis/cart';
import { showToast } from 'vant';
export default {
    data(){
        return{
            userid:''
        }
    },
    methods:{
        addToCart(){
            doAddCart({userid:this.userid,proid:this.$route.params.proid,num:1}).then(res=>{
                if(res.data.code!='200') return showToast("加入购物车失败")
                showToast("加入购物车成功")
            this.$router.push("/cart")
            })
        }
    },
    created(){
        this.userid=localStorage.getItem('userid')
    }

}
</script>

<style lang="less" scoped></style>